
###
### This Makefile is about building the Fedora and OLPC RPMs/SRPMs for
### the Squeak and Etoys packages.
### It will download (or build) the upstream sources (tarballs or zip files)
### and build the RPMs and SRPMs.
###
### The configuration macros are commented below.  The primary Make rules
### are also commented below.
### 
### The quickstart version is:
###  * Make sure that the config macros below (primarily the XXX_VERSION
###       ones) are set the same as in the xxx.spec files.  
###  * run "make"
###     this will build all the rpms and srpms
###




##
## Configuration macros, 
## Most of the following macros must be the same as those in the coorisponding
## .spec file.  That is Makefile macro XXX_YYY must be the same as the
## .spec file macro yyy in xxx.spec.  It's simpler than it sounds.
## It would be possible and safer to automate the setting of these macros
## by grep-ing/sed-ing the values from the spec file directly, but I haven't
## taken the time to do that.
##
## These macros are not taken from the .spec files:
##
## XXX_REMAKEABLE_SOURCES
##   it is the list of files that can be re-made either by building them
##   or downloading them.  It is used by "make clean"
##
## XXX_BASENAME is always the basename of XXX
## XXX_ALLSOURCES is all the SOURCE and PATCH files that go into XXX
## XXX_SPEC is the spec file name for XXX
##

MOCK_ROOT=fedora-9-i386


SQUEAK_VM_MAJOR=3.10
SQUEAK_VM_MINOR=4
SQUEAK_VM_SOURCE0=http://squeakvm.org/unix/release/Squeak-${SQUEAK_VM_MAJOR}-${SQUEAK_VM_MINOR}.src.tar.gz
SQUEAK_VM_SOURCE2=squeak-desktop-files.tar.gz
SQUEAK_VM_PATCH0=squeak-vm-rpath.patch
SQUEAK_VM_PATCH1=squeak-vm-install-inisqueak.patch
SQUEAK_VM_PATCH2=squeak-vm-imgdir.patch
SQUEAK_VM_PATCH3=squeak-vm-tail-options.patch
SQUEAK_VM_SOURCE0_BASENAME:=$(shell basename ${SQUEAK_VM_SOURCE0})
SQUEAK_VM_REMAKEABLE_SOURCES=${SQUEAK_VM_SOURCE0_BASENAME}
SQUEAK_VM_ALLSOURCES=${SQUEAK_VM_SOURCE0_BASENAME} ${SQUEAK_VM_SOURCE1} ${SQUEAK_VM_SOURCE2} ${SQUEAK_VM_PATCH0} ${SQUEAK_VM_PATCH1} ${SQUEAK_VM_PATCH2} ${SQUEAK_VM_PATCH3}
SQUEAK_VM_SPEC=squeak-vm.spec

#SQUEAK_VM_SOURCE0=http://ftp.squeak.org/${SQUEAK_VM_MAJOR}/unix-linux/Squeak-${SQUEAK_VM_MAJOR}-${SQUEAK_VM_MINOR}.src.tar.gz
#SQUEAK_VM_SOURCE1=squeak-vm-tarball-from-svn.sh
#SQUEAK_VM_SOURCE0_COMMAND=sh ${SQUEAK_VM_SOURCE1} ${SQUEAK_VM_SOURCE0_SVN} ${SQUEAK_VM_SOURCE0_BASENAME}
#SQUEAK_VM_SOURCE0_SVN=http://squeakvm.org/svn/squeak/branches/olpc



SQUEAK_IMAGE_IMAGE_VERSION=3.10.2-7179
SQUEAK_IMAGE_SOURCES_VERSION=V39
SQUEAK_IMAGE_SOURCE0=http://ftp.squeak.org/${SQUEAK_VM_MAJOR}/Squeak${SQUEAK_IMAGE_IMAGE_VERSION}-basic.zip
SQUEAK_IMAGE_SOURCE0_BASENAME:=$(shell basename ${SQUEAK_IMAGE_SOURCE0})
SQUEAK_IMAGE_SOURCE1=http://ftp.squeak.org/sources_files/Squeak${SQUEAK_IMAGE_SOURCES_VERSION}.sources.gz
SQUEAK_IMAGE_SOURCE1_BASENAME:=$(shell basename ${SQUEAK_IMAGE_SOURCE1})
SQUEAK_IMAGE_SOURCE2=squeak-image-doc.html
SQUEAK_IMAGE_REMAKEABLE_SOURCES=${SQUEAK_IMAGE_SOURCE0_BASENAME} ${SQUEAK_IMAGE_SOURCE1_BASENAME}
SQUEAK_IMAGE_ALLSOURCES=${SQUEAK_IMAGE_SOURCE0_BASENAME} ${SQUEAK_IMAGE_SOURCE1_BASENAME} ${SQUEAK_IMAGE_SOURCE2}
SQUEAK_IMAGE_SPEC=squeak-image.spec

ETOYS_VERSION=4.0.2201
ETOYS_SOURCE0=http://download.sugarlabs.org/sources/sucrose/glucose/etoys/etoys-${ETOYS_VERSION}.tar.gz
ETOYS_SOURCE0_BASENAME:=$(shell basename ${ETOYS_SOURCE0})
ETOYS_SOURCE2=etoys.desktop
ETOYS_SOURCE3=etoys.png
ETOYS_REMAKEABLE_SOURCES=${ETOYS_SOURCE0_BASENAME}
ETOYS_ALLSOURCES=${ETOYS_SOURCE0_BASENAME} ${ETOYS_SOURCE1} ${ETOYS_SOURCE2} ${ETOYS_SOURCE3}
ETOYS_SPEC=etoys.spec

# before the 4.0 release i could not find an actual Etoys tarball, so etoys-tarball-from-srpm.sh
#ETOYS_SOURCE0_COMMAND=sh etoys-tarball-from-srpm.sh ${ETOYS_UPSTREAM_SRPM} ${ETOYS_SOURCE0_BASENAME}
#ETOYS_UPSTREAM_SRPM=http://etoys.laptop.org/srpm/etoys-${ETOYS_VERSION}-1.src.rpm
#ETOYS_SOURCE1=etoys-tarball-from-srpm.sh

# also we have a git command too in case, but no publicly announced tags
#ETOYS_SOURCE0_COMMAND=sh etoys-tarball-from-git.sh ${ETOYS_UPSTREAM_GIT} ${ETOYS_SOURCE0_BASENAME}
#ETOYS_UPSTREAM_GIT=git://dev.laptop.org/projects/etoys
#ETOYS_SOURCE1=etoys-tarball-from-git.sh



#
# The following are rpm values needed by this makefile
# 
SOURCEDIR:=$(shell rpm --eval '%{_sourcedir}')
SPECDIR:=$(shell rpm --eval '%{_specdir}')
ALLBUILDDIRS:=$(shell rpm --eval '%{_builddir} %{_srcrpmdir} %{_rpmdir}')


.PHONY: all default
all default: all-rpms

.PHONY: install-build-requires
install-build-requires:
	sudo yum install libX11-devel libXt-devel libvorbis-devel libtheora-devel speex-devel dbus-devel alsa-lib-devel pango-devel gstreamer-devel mesa-libGL-devel libICE-devel libSM-devel libXext-devel e2fsprogs-devel



##
## For each of the four packages (squeak-vm,squeak-image,squeak-sources,etoys)
## you can build the RPM (-rpm), or the SRPM (-srpm), or both (-rpms)
## For example, 
##    to build the squeak-vm RPM, use "make squeak-vm-rpm"
##    to build the squeak-sources SRPM, use "make squeak-sources-srpm"
##    to build the squeak-images RPM and SRPM, "make squeak-images-rpms"
## Or you can build 
##      all-rpm (the RPMs for all 4 packages)
##      all-srpm (the SRPMs for all 4 packages)
##      all-rpms (the RPMs and SRPMs for all 4 packages)
##
all-rpms: squeak-vm-rpms squeak-image-rpms etoys-rpms
all-srpm: squeak-vm-srpm squeak-image-srpm etoys-srpm
all-rpm: squeak-vm-rpm squeak-image-rpm etoys-rpm
all-mock: squeak-vm-mock squeak-image-mock etoys-mock

##
## clean out the REMAKEABLE stuff
##
.PHONY: clean
clean:
	rm -rf squeak-desktop-files.tar.gz ${SQUEAK_VM_REMAKEABLE_SOURCES} ${SQUEAK_IMAGE_REMAKEABLE_SOURCES} ${ETOYS_REMAKEABLE_SOURCES} rpmbuild








squeak-vm-rpms: ${SPECDIR}/${SQUEAK_VM_SPEC} $(patsubst %, ${SOURCEDIR}/%, ${SQUEAK_VM_ALLSOURCES})
	mkdir -p ${ALLBUILDDIRS}
	rpmbuild -ba $<

squeak-vm-srpm: ${SPECDIR}/${SQUEAK_VM_SPEC} $(patsubst %, ${SOURCEDIR}/%, ${SQUEAK_VM_ALLSOURCES})
	mkdir -p ${ALLBUILDDIRS}
	rpmbuild -bs $<

squeak-vm-rpm: ${SPECDIR}/${SQUEAK_VM_SPEC} $(patsubst %, ${SOURCEDIR}/%, ${SQUEAK_VM_ALLSOURCES})
	mkdir -p ${ALLBUILDDIRS}
	rpmbuild -bb $<

squeak-vm-prep: ${SPECDIR}/${SQUEAK_VM_SPEC} $(patsubst %, ${SOURCEDIR}/%, ${SQUEAK_VM_ALLSOURCES})
	mkdir -p ${ALLBUILDDIRS}
	rpmbuild -bp $<

squeak-image-rpms: ${SPECDIR}/${SQUEAK_IMAGE_SPEC} $(patsubst %, ${SOURCEDIR}/%, ${SQUEAK_IMAGE_ALLSOURCES})
	mkdir -p ${ALLBUILDDIRS}
	rpmbuild -ba $<

squeak-image-srpm: ${SPECDIR}/${SQUEAK_IMAGE_SPEC} $(patsubst %, ${SOURCEDIR}/%, ${SQUEAK_IMAGE_ALLSOURCES})
	mkdir -p ${ALLBUILDDIRS}
	rpmbuild -bs $<

squeak-image-rpm: ${SPECDIR}/${SQUEAK_IMAGE_SPEC} $(patsubst %, ${SOURCEDIR}/%, ${SQUEAK_IMAGE_ALLSOURCES})
	mkdir -p ${ALLBUILDDIRS}
	rpmbuild -bb $<

etoys-rpms: ${SPECDIR}/${ETOYS_SPEC} $(patsubst %, ${SOURCEDIR}/%, ${ETOYS_ALLSOURCES})
	mkdir -p ${ALLBUILDDIRS}
	rpmbuild -ba $<

etoys-srpm: ${SPECDIR}/${ETOYS_SPEC} $(patsubst %, ${SOURCEDIR}/%, ${ETOYS_ALLSOURCES})
	mkdir -p ${ALLBUILDDIRS}
	rpmbuild -bs $<

etoys-rpm: ${SPECDIR}/${ETOYS_SPEC} $(patsubst %, ${SOURCEDIR}/%, ${ETOYS_ALLSOURCES})
	mkdir -p ${ALLBUILDDIRS}
	rpmbuild -bb $<


squeak-vm-mock: squeak-vm-srpm
	sudo mock -r ${MOCK_ROOT} --resultdir=./mock/squeak-vm --rebuild rpmbuild/SRPMS/squeak-vm-*.src.rpm

squeak-image-mock: squeak-image-srpm
	sudo mock -r ${MOCK_ROOT} --resultdir=./mock/squeak-image --rebuild rpmbuild/SRPMS/squeak-image-*.src.rpm

etoys-mock: etoys-srpm
	sudo mock -r ${MOCK_ROOT} --resultdir=./mock/etoys --rebuild rpmbuild/SRPMS/etoys-*.src.rpm

KOJI_TAG=dist-f9

squeak-vm-koji: squeak-vm-srpm
	koji build --scratch ${KOJI_TAG} rpmbuild/SRPMS/squeak-vm-*.src.rpm

squeak-image-koji: squeak-image-srpm
	koji build --scratch ${KOJI_TAG} rpmbuild/SRPMS/squeak-image-*.src.rpm

etoys-koji: etoys-srpm
	koji build --scratch ${KOJI_TAG} rpmbuild/SRPMS/etoys-*.src.rpm

${SPECDIR}/%: %
	mkdir -p $(dir $@)
	cp  $< $@

${SOURCEDIR}/%: %
	mkdir -p $(dir $@)
	cp  $< $@

${SOURCEDIR}/${SQUEAK_VM_SOURCE0_BASENAME}: ${SQUEAK_VM_SOURCE0_BASENAME}
	mkdir -p $(dir $@)
	cp $< $@



.PRECIOUS: ${SQUEAK_VM_SOURCE0_BASENAME}
${SQUEAK_VM_SOURCE0_BASENAME}: 
ifdef SQUEAK_VM_SOURCE0_COMMAND
	${SQUEAK_VM_SOURCE0_COMMAND}
else
	wget ${SQUEAK_VM_SOURCE0}
endif

.PRECIOUS: ${SQUEAK_IMAGE_SOURCE1_BASENAME}
${SQUEAK_IMAGE_SOURCE1_BASENAME}: 
	wget ${SQUEAK_IMAGE_SOURCE1}	

.PRECIOUS: ${SQUEAK_IMAGE_SOURCE0_BASENAME}
${SQUEAK_IMAGE_SOURCE0_BASENAME}: 
	wget ${SQUEAK_IMAGE_SOURCE0}

.PRECIOUS: ${ETOYS_SOURCE0_BASENAME}
${ETOYS_SOURCE0_BASENAME}: 
ifdef ETOYS_SOURCE0_COMMAND
	${ETOYS_SOURCE0_COMMAND}
else
	wget ${ETOYS_SOURCE0}
endif


squeak-desktop-files.tar.gz: mysqueak mysqueak.1 squeak.desktop squeak.xml squeak.png squeak16.png squeak24.png squeak32.png squeak48.png squeak64.png squeak72.png squeak96.png squeaksource.png squeaksource16.png squeaksource24.png squeaksource32.png squeaksource48.png squeaksource64.png squeaksource72.png squeaksource96.png
	tar zcf $@ $^





